package dev.touchswipe.shared.touchLib
{
	import flash.events.TouchEvent;

	public class TouchManager
	{
		private var _touchPoints:Object;
		
		public function TouchManager()
		{
			_touchPoints=new Object();
		}
		
		public function getUpdatedPoint(event:TouchEvent):TouchPoint{
			updatePoint(event);
			return _touchPoints[event.touchPointID];
		}
		
		public function updatePoint(event:TouchEvent):void{
			if(event.type==TouchEvent.TOUCH_BEGIN){
				if(_touchPoints[event.touchPointID])
					_activePoints--;
				_touchPoints[event.touchPointID]=new TouchPoint(event);
				_activePoints++;
				return 
			}
			else if(event.type==TouchEvent.TOUCH_MOVE){
				TouchPoint(_touchPoints[event.touchPointID]).update(event);
				return
			}
			else if(event.type==TouchEvent.TOUCH_END){
				_touchPoints[event.touchPointID]=null;
				_activePoints--;
				return
			}
			return
		}
		
		private var _activePoints:int;
		public function get activePoints():int{
			return _activePoints;
		}
		
		public function getCurrentPoints():Vector.<TouchPoint>{
			var result:Vector.<TouchPoint>=new Vector.<TouchPoint>();
			for each(var t:TouchPoint in _touchPoints)
				result.push(t);
			return result;
		}
	}
}